<?php
	//引入DH映射表
	$attr_mapping = require('attr_mapping.php');
	$tmp_arr = array();
	$sql = "
		SELECT 
		product_id,
		goods_id,
		bn,
		price,
		mktprice,
		store
		FROM ". $this->_dbPrefix. "products 
		WHERE 
		marketable='true'
		AND goods_id=". $product_id;
	$rs = $this->_dbObj->getArray($sql);
	
	foreach($rs as $item){ //循环多少条属性
		$sql = "
			SELECT 
			gsi.goods_id,
			gsi.product_id,
			s.spec_name,
			sv.spec_value
			FROM ". $this->_dbPrefix. "goods_spec_index gsi
			LEFT JOIN ". $this->_dbPrefix. "specification s ON gsi.spec_id=s.spec_id
			LEFT JOIN ". $this->_dbPrefix. "spec_values sv ON gsi.spec_value_id=sv.spec_value_id
			WHERE gsi.product_id=". $item['product_id'];
		$rst = $this->_dbObj->getArray($sql);
		foreach($rst as $value){ //循环得到text
			//type
			foreach($attr_mapping as $v){
				if(preg_match('/(^|,| )'.preg_quote($value['spec_name']).'(,| |$)/i', $v['keyword'])){
					$type = $v['mapping'];
					break;
				}
			}//end type
			$text_arr[$type] = array($value['spec_value']);
		}

		$tmp_arr[] = array(
			'tpye'=>'',
			'text'=>json_encode($text_arr),
			'value'=>json_encode(array('marketing'=>$item['mktprice'], 'current'=>$item['price'])),
			'ext'=>json_encode(array('stock'=>$item['store'])),
			'status'=>'2',
		);
	}

	return $tmp_arr;

?>